﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.MenuaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.MenuaLL
{
    public class FirstMenusCommandHandler : IRequestHandler<FirstMenusCommand, ApiResult<Menus>>
    {
        IBaseReponsitory<Menus> Menus;

        public FirstMenusCommandHandler(IBaseReponsitory<Menus> Menus)
        {
            this.Menus = Menus;
        }

        public async Task<ApiResult<Menus>> Handle(FirstMenusCommand request, CancellationToken cancellationToken)
        {
            var list =await Menus.GetQuery().FirstOrDefaultAsync(c=>c.Menu_Id==request.MenuId);
            return new ApiResult<Menus> 
            {
                Code=ApiEnum.Success,
                Message="获取成功",
                Data=list
            };
        }
    }
}
